package py.edu.ucom.cadira.net.serializables;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.net.XMLSerializable;

/*
 * CHEQUEADO CON CLASES DE BLAS (Login)
 * */
public class LoginRequest implements XMLSerializable {
	private String username;
	private String password;
	
	public LoginRequest(){
		
	}
	
	public LoginRequest(String username, String password) {
		super();
		this.username = username;
		this.password = password;
	}


	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public void fromXML(Document xml) {
		Element root = xml.getRootElement();
		Element loginNode = root.getChild("login");
		Element usernameNode = loginNode.getChild("username");
		Element passwordNode = loginNode.getChild("password");
		setPassword(passwordNode.getValue());
		setUsername(usernameNode.getValue());

	}

	public void toXML(Element root) {

		Element nodeLogin = new Element("login");
		Element nodeUsername = new Element("username");
		Element nodePasswd = new Element("password");

		nodeUsername.setText(getUsername());
		nodePasswd.setText(getPassword());
		nodeLogin.addContent(nodeUsername);
		nodeLogin.addContent(nodePasswd);

		root.addContent(nodeLogin);
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof LoginRequest)) {
			return false;
		}
		LoginRequest otherObj = (LoginRequest) obj;
		if (otherObj.getUsername().equals(getUsername())
				&& otherObj.getPassword().equals(getPassword())) {
			return true;
		}
		return false;
	}
}